﻿using JeanFish.Security;
using System;
using System.Text;

namespace JeanFish.UnitTest.Security
{

    public partial class HashHelperTest
    {
        IHashAlgorithmFactory factory = null;

        partial void InitializeSample()
        {
            factory = HashAlgorithmFactory.Current;
            sample = "password";
            actual_md5 = "5f4dcc3b5aa765d61d8327deb882cf99";
            actual_sha256 = "5E884898DA28047151D0E56F8DC6292773603D0D6AABBDD62A11EF721D1542D8";
            actual_sha512 = "B109F3BBBC244EB82441917ED06D618B9008DD09B3BEFD1B5E07394C706A8BB980B1D7785E5976EC049B46DF5F1326AF5A2EA6D103FD07C95385FFAB0CACBC86";
        }
        partial void TestMD5ComputeHash(string sample, ref string hash)
        {
            var data = Encoding.UTF8.GetBytes(sample);
            var md5 = factory.GetHashAlgorithm(factory.MD5);
            bool hashType=md5.AlgorithmsType == factory.MD5;
            var hash0 = md5.ComputeHash(data);
            hash=BitConverter.ToString(hash0).Replace("-", "").ToLower();
            var result = md5.VerifyHash(data, hash0);
        }
        partial void TestSHA256ComputeHash(string sample, ref string hash)
        {
            var data = Encoding.UTF8.GetBytes(sample);
            var sha256 = factory.GetHashAlgorithm(factory.SHA256);
            var hash0 = sha256.ComputeHash(data);
            hash = BitConverter.ToString(hash0).Replace("-", "").ToUpper();
            var result = sha256.VerifyHash(data, hash0);
        }
        partial void TestSHA512ComputeHash(string sample, ref string hash)
        {
            var data = Encoding.UTF8.GetBytes(sample);
            var sha512 = factory.GetHashAlgorithm(factory.SHA512);
            var hash0 = sha512.ComputeHash(data);
            hash = BitConverter.ToString(hash0).Replace("-", "").ToUpper();
            var result = sha512.VerifyHash(data, hash0);
        }
        partial void TestNotSupportedHashAlgorithm(string data, ref string hash)
        {
            var notSupportedFactory = factory.GetHashAlgorithm("test");
        }
    }
}
